﻿using System.Collections.Generic;
using System.Windows.Forms;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraTreeList;
using HuaCheng.Controller;
using HuaCheng.DataAccess;

namespace HuaCheng.Views
{
    public partial class Allocation : Form
    {
        //为去除自带右键菜单
        RepositoryItem TextEdit = new RepositoryItemTextEdit();
        //描述列不可编辑
        RepositoryItem TextNoEdit = new RepositoryItemTextEdit();
        public Allocation()
        {
            InitializeComponent();
            TextEdit.MouseDown += tlConfiguration_MouseDown;
            TextNoEdit.ReadOnly = true;
            //加载配置信息
            LoadAllocation();
        }

        private void tlConfiguration_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                TreeListHitInfo hInfo = tlConfiguration.CalcHitInfo(new System.Drawing.Point(e.X, e.Y));
                tlConfiguration.FocusedNode = hInfo.Node;
            }
        }
        /// <summary>
        /// 描述那一列不可编辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tlConfiguration_CustomNodeCellEdit(object sender, DevExpress.XtraTreeList.GetCustomNodeCellEditEventArgs e)
        {
            e.RepositoryItem = TextEdit;
            if (e.Column.Name == "tlDescription")
            {
                e.RepositoryItem = TextNoEdit;
            }
        }
        /// <summary>
        /// 读取配置信息
        /// </summary>
        private void LoadAllocation()
        {
            List<Dicts> alloList = DicHelper.RetrieveAllocation();
            AllocationControl.SetTreeListByAlloList(alloList, tlConfiguration);
        }
        /// <summary>
        /// 取消按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void btnCancel_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }
    }
}
